local zhaobing = fk.CreateSkill {
  name = "zhaobing",
}

zhaobing:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Finish and not player:isKongcheng() and
      table.find(player:getCardIds("h"), function (id)
        return not player:prohibitDiscard(id)
      end)
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#zhaobing-invoke")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = player:getHandcardNum()
    player:throwAllCards("h")
    if player.dead then return end
    local targets = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player, false), Util.IdMapper), 1, n,
      "#zhaobing-choose:::"..n, self.name, true)
    if #targets == 0 then return end
    room:sortPlayersByAction(targets)
    for _, id in ipairs(targets) do
      local p = room:getPlayerById(id)
      if not p.dead then
        if p:isKongcheng() or player.dead then
          room:loseHp(p, 1, self.name)
        else
          local card = room:askForCard(p, 1, 1, false, self.name, true, "slash", "#zhaobing-card:"..player.id)
          if #card > 0 then
            p:showCards(card)
            if not player.dead and table.contains(p:getCardIds("h"), card[1]) then
              room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonGive, self.name, nil, true, p)
            end
          else
            room:loseHp(p, 1, self.name)
          end
        end
      end
    end
  end,
})

return zhaobing